<template>
	<view>
		<view class="keepEdit_box">
			


			<view class="handleList_box">
				
				<view class="handleList_con">
					<view class="handleLabel">类型：</view>
					<view class="handleList">
						<view :class="'handleItem '+(selectType==1?'handleActive':'')" @click="typeClick(1)">点工
						</view>
						<view :class="'handleItem '+(selectType==2?'handleActive':'')" @click="typeClick(2)">包工
						</view>
					</view>
				</view>
				<view class="handleList_con" v-if="selectType==1">
					<view class="handleLabel">上班：</view>
					<view class="handleList">
						<view :class="'handleItem '+(workType==1?'handleActive':'')" @click="workTypeSelect(1)">1工
						</view>
						<view :class="'handleItem '+(workType==2?'handleActive':'')" @click="workTypeSelect(2)">0.5工
						</view>
						<view :class="'handleItem '+(workType==3?'handleActive':'')" @click="workTypeSelect(3)">休息
						</view>
						<view :class="'handleItem '+(workType==4?'handleActive':'')" @click="workTypeSelect(4)">
							<input type="digit" :value="workInput" @input="workNumInput" placeholder="自定义">
						</view>
					</view>
				</view>
				<view class="handleList_con" v-if="selectType==1">
					<view class="handleLabel">加班：</view>
					<view class="handleList">
						<view :class="'handleItem '+(selectOver==1?'handleActive':'')" @click="openWorkPopup(1)">
							无加班
						</view>
						<view :class="'handleItem '+(selectOver==2?'handleActive':'')" style="flex: 2;"
							@click="openWorkPopup(2)" v-if="defaultWorksite.work_type==0">
							<view class="overInput">{{(selectOver==2 && overWork>0) ? overWork+'工' : '按工算'}}</view>
							<view class="overLine"></view>
							<image src="/static/keep/editBtn.png" mode="" class="overIcon"></image>
						</view>
						<view :class="'handleItem '+(selectOver==3?'handleActive':'')" style="flex: 2;"
							@click="openWorkPopup(3)">
							<view class="overInput">{{(selectOver==3 && overWork>0) ? overWork+'时' : '按小时'}}</view>
							<view class="overLine"></view>
							<image src="/static/keep/editBtn.png" mode="" class="overIcon"></image>
						</view>
					</view>
				</view>
				<view class="handleList_con" v-if="selectType==2">
					<view class="handleLabel">金额：</view>
					<view class="handleList">
						<view class="baoCon">
							<input type="number"  :value="workInput" @input="workNumInput" placeholder="点击输入金额"
								placeholder-class="placeholderColor">
							<text>元/人</text>
						</view>
					</view>
				</view>

				
				
			</view>
			
			
			<view class="handlePost_con">
				<view class="completeBtn"  @click="addSubmit">确定</view>
			</view>
		</view>
		
		<!-- 上传图片组件 -->
		<Upload v-if="isUpload" type="jigong" @getImgs="getImgsFunc"></Upload>

		<!-- 选择工时组件 -->
		<WorkHour ref="workHour"></WorkHour>

	</view>
</template>

<script>
	import Upload from '@/components/upload/uploadAlbum.vue';
	import WorkHour from "@/components/keep/workHour.vue"
	import {
		gegerateDates,
		dateEqual,
		formatDate
	} from '@/util/generateDates.js';

	export default {
		components: {
			Upload,
			WorkHour,
		},

		data() {
			return {
				// 默认工地信息
				defaultWorksite: JSON.parse(uni.getStorageSync('defaultWorksite')),

				// 编辑弹窗
				editShow: false,
				dayNum: formatDate(new Date(), 'yyyy-MM-dd'),

				// 记工详情
				workDetail: {},

				// 记工
				selectType: 1,
				workType: 0,
				workNum: -1, //提交的工
				workInput: '', //输入的工
				overWork: 0, //加班
				selectOver: 1,
				remark:'',
				// 上传图片
				isUpload: false,
				imgList: [],
				id:'',
			};
		},
		onLoad(e) {
			console.log('e')
			console.log(e)
			var _this = this;
			_this.selectType = 1;
			_this.workType = 0;
			_this.workNum = -1;
			_this.workInput = '';
			_this.overWork = 0;
			_this.selectOver = 1;
			_this.id=e.id;
			
		},
		
		onShow(){
			var _this=this;
			
			
			
			
		},
		methods: {
			
			
			

			// 选择记工类型
			typeClick(type) {
				this.selectType = type;
			},

			// 自定义工输入
			workNumInput(e) {
				this.workNum = e.detail.value;
				this.workInput = e.detail.value;
			},

			// 上班类型选择
			workTypeSelect(type) {
				this.workType = type;
				var workNum = 1;
				if (type == 1) {
					workNum = 1;
				}
				if (type == 2) {
					workNum = 0.5;
				}
				if (type == 3) {
					workNum = '休';
				}
				this.workNum = workNum;
			},
			
			
			
			// 上传图片
			

			// 选择日期
			openWorkPopup(type) {
				this.selectOver = type;
				if (type == 1) {
					this.overWork = 0;
					return
				}
				this.$refs.workHour.workShow = true;
				this.$refs.workHour.doingType = type;
			},

			// 关闭设定弹窗
			closeClick() {
				this.editShow = false;
			},

			// 删除记工数据
			delClick() {
				var _this = this;
				uni.showModal({
					title: '提示',
					content: '是否确定删除此记工？',
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定');
							_this.$u.post('/api/project.work/delete_do', {
								id: _this.workDetail.id,
							}).then(res => {
								console.log("==删除记工==");
								console.log(res);
								uni.showToast({
									title: res.msg,
									duration: 2000
								});
								setTimeout(function() {
									uni.navigateBack()
								}, 2000)
							}).catch(res => {
								console.log(res);
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			addSubmit() {
				var _this = this;
				console.log(_this.logIds)
				if (!_this.dayNum) {
					uni.showModal({
						content: '请选择日期',
						showCancel: false,
					})
					return;
				}
				// role:1工人 2带班 3老板
				_this.$u.throttle(_this.recordSubmit, 3000);

			},

			recordSubmit() {
				var _this = this;
				if (_this.selectType == 1) {
					// 点工
					var para = {
						num: _this.workNum,
						price: 0,
						
					}
					para['overtime_hour'] = 0;
					para['overtime_days'] = 0;
				} else if (_this.selectType == 2) {
					// 包工
					var para = {
						num: 0,
						price: _this.workNum,
					}
				}

				if (_this.selectOver == 2) {
					para['overtime_days'] = _this.overWork;
					para['overtime_hour'] = 0;
				}
				if (_this.selectOver == 3) {
					para['overtime_hour'] = _this.overWork;
					para['overtime_days'] = 0;
				}
				
				para.selectType=_this.selectType;
				para.selectOver=_this.selectOver;
				para.overWork=_this.overWork;
				
				uni.setStorageSync('cameraWork', JSON.stringify(para));
				uni.navigateBack()
				
			},

			// 更新对比数据
			updateCompare() {
				var _this = this;
				var workDetail = _this.workDetail;
				_this.$u.post('/api/project.compare/projectCompare', {
					project_id: _this.defaultWorksite.project_id,
					type: '1', //1记工、2记账
					add_date: workDetail.add_date,
					member_id: workDetail.member_id,
				}).then(res => {
					console.log(res)
					console.log("==更新对比数据==")
					_this.getCheckCompare()
				}).catch(res => {
					console.log(res);
				})
			},

			// 获取记工偏差
			getCheckCompare() {
				var _this = this;
				_this.$u.get('/api/project.compare/checkCompare', {
					project_id: _this.defaultWorksite.project_id,
					type: '1', //1记工、2记账
				}).then(res => {
					uni.hideLoading();
					console.log("==获取记工偏差==");
					console.log(res);
					var resData = res.data;
					if (resData > 0) {
						_this.isError = true;
					} else {
						_this.isError = false;
					}
				}).catch(res => {
					console.log(res);
				})
			},

			// 弹出框关闭处理
			overWorkUpdate() {

			},

		},
	}
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	/* 修改记工弹窗 */
	.keepEdit_box {
		max-height: 90vh;
		overflow-y: scroll;
	}

	.setHead_con {
		padding: 30rpx;
		overflow: hidden;
	}

	.setTit {
		width: 100%;
		font-size: 32rpx;
		font-weight: bold;
		color: #000;
		text-align: center;
	}

	.handleList_box {
		padding: 15rpx 30rpx;
	}

	.handPost_con {
		padding: 30rpx;
		border-top: 1rpx solid #eee;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.handlePost_con{
		position: relative;
	}
	.handlePost_con .completeBtn{
		margin-right:20rpx;
	}
	.handlePost_con .completeBtn:last-child{
		margin-right:0rpx;
	}

	.delBtn {
		
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 28rpx;
		color: #FF4241;
		border: 2rpx solid #ff4241;
		border-radius: 10rpx;
		overflow: hidden;
		background-color: #fff;
		margin-right: 0;
	}
	
	.saveBtn {
		width: 430rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		background-color: #327FE8;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.handlePost_con {
		position: fixed;
		bottom: 20rpx;
		padding-top: 30rpx;
		border-top: 0;
	}

	.toRight {
		margin-right: 20rpx;
	}
	
	
	.handleList_con .textareaCon textarea {
		height: 240rpx;
		vertical-align: top;
	}
	
	.uploadList .uploadItem image {
		height: 140rpx;
		width: 140rpx;
	}
	
	.uploadList .uploadItem{
		height: 140rpx;
		width: 140rpx;
	}
	
	.handleLabelTwo{
		width: 150rpx;
	}
</style>
